<template>
  <div class="app-container" >

    <el-form ref="form" label-position="top" :model="form" :rules="rules" label-width="80px">
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="所属客户" prop="customerId">
            <el-select v-model="form.customerId" placeholder="请选择所属客户" class="w100" disabled>
              <el-option
                v-for="item in customerList"
                :key="item.id"
                :label="item.companyName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div style="width: 100%;background-color: lightgray;height: 25px;align-items: center;">
            <div style="border-left: 10px;color: blue;"></div>
            <span style="text-align: center;">联系人信息</span>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="sex">
            <el-select v-model="form.sex" placeholder="请选择性别" class="w100">
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="手机号码" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入手机号码" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="职务" prop="position">
            <el-input v-model="form.position" placeholder="请输入职务" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="决策角色" prop="decisionRole">
            <el-select v-model="decisionRoleList" multiple placeholder="请选择决策角色" class="w100" @change="handleDecisionRoleChange">
              <el-option
                v-for="dict in dict.type.zxcrm_decision_role"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="关系等级" prop="relationshipLevel">
            <el-select v-model="form.relationshipLevel" placeholder="请选择关系等级" class="w100">
              <el-option
                v-for="dict in dict.type.zxcrm_relationship_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="籍贯" prop="nativePlace">
            <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生日" prop="birthday" >
            <el-date-picker clearable  style="width: 100%;"
              v-model="form.birthday"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择生日">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="态度类别" prop="attitudeCategory">
            <el-select v-model="form.attitudeCategory" placeholder="请选择态度类别" class="w100">
              <el-option
                v-for="dict in dict.type.zxcrm_attitude_category"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="直属上司" prop="immediateSupervisorId">
            <el-select v-model="form.immediateSupervisorId" filterable placeholder="请选择沟通风格" class="w100">
              <el-option
                v-for="item in contactList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
               <span style="float: left">{{ item.name }}</span>
               <span style="float: right; color: #8492a6; font-size: 13px">{{ item.customerCompanyName }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="沟通风格" prop="communicationStyle">
            <el-select v-model="communicationStyleList" multiple placeholder="请选择沟通风格" class="w100" @change="handleCommunicationStyleList">
              <el-option
                v-for="dict in dict.type.zxcrm_communication_style"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="对对接人的要求" prop="contactPersonRequire">
            <el-input v-model="form.contactPersonRequire" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="对供应商的要求" prop="supplierRequire">
            <el-input v-model="form.supplierRequire" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="兴趣爱好" prop="hobby">
            <el-input v-model="form.hobby" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="往期履历" prop="previousResume">
            <el-input v-model="form.previousResume" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="抽烟情况" prop="smokingSituation">
            <el-input v-model="form.smokingSituation" placeholder="请输入抽烟情况" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="喝酒情况" prop="drinkingSituation">
            <el-input v-model="form.drinkingSituation" placeholder="请输入喝酒情况" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="婚姻状况" prop="maritalStatus">
            <el-select v-model="form.maritalStatus" placeholder="请选择婚姻状况" class="w100">
              <el-option
                v-for="dict in dict.type.zxcrm_marital_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="家庭情况" prop="familySituation">
            <el-input v-model="form.familySituation" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="社会关系说明" prop="socialRelationshipsExplanation">
            <el-input v-model="form.socialRelationshipsExplanation" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="邮件地址" prop="mailingAddress">
            <el-input v-model="form.mailingAddress" placeholder="请输入邮件地址" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="家庭住址" prop="homeAddress">
            <el-input v-model="form.homeAddress" placeholder="请输入家庭住址" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="gutter">
        <el-col :span="12">
          <el-form-item label="其他备注" prop="otherRemarks">
            <el-input v-model="form.otherRemarks" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer"  class="flex-right">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
    </div>
  </div>
</template>

<script>
  import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/zxcrm/customer"
  export default{
    name:"customerUpdate",
    dicts: ['zxcrm_relationship_level', 'zxcrm_communication_style', 'zxcrm_attitude_category', 'zxcrm_decision_role', 'sys_user_sex', 'zxcrm_marital_status'],
    props:{
      form:{
        default:{}
      },
      contactList:{
        default:[]
      },
      customerList:{
        default:[]
      }
    },
    data() {
      return{
        decisionRoleList:[],
        communicationStyleList:[],
        gutter:20,
        // 表单校验
        rules: {
          customerId: [
            { required: true, message: '所属客户是必填项', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '姓名是必填项', trigger: 'blur' }
          ],
        }
      }
    },
    created(){
      this.reset()
      this.setDate()
    },
    methods:{
      setDate(){
        if(this.form.decisionRole){
          this.decisionRoleList = this.form.decisionRole.split(",")
        }
        if(this.form.communicationStyle){
          this.communicationStyleList = this.form.communicationStyle.split(",")
        }
      },
      /** 决策角色改变 */
      handleDecisionRoleChange(e){
        this.form.decisionRole = e.join(",")
      },
      /** 沟通风格改变 */
      handleCommunicationStyleList(e){
        this.form.communicationStyle = e.join(",")
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.$emit('updateContact',this.form)
              // updateCustomer(this.form).then(response => {
              //   this.$modal.msgSuccess("修改成功")
              // })
            } else {
              console.log("11111111111");
               this.$emit('addContact',this.form)
              // addCustomer(this.form).then(response => {
              //   this.$modal.msgSuccess("新增成功")
              // })
            }
          }
        })
      },

      reset() {
        this.mainSalesProduct = []
        this.basicInfoForm = {
          id: null,
          companyName: null,
          companyAbbreviation: null,
          customerClassify: null,
          customerLevel: null,
          operateAddress: null,
          actualControllerId: null,
          vaccineDepartmentHeadId: null,
          purchaseDockingId: null,
          warehouseOperatorId: null,
          userId: null,
          financeId: null,
          area: null,
          customerType: null,
          competitor: null,
          mainSalesProduct: null,
          customerReloationship: null,
          customerOrganizationalRelationship: null,
          other: null,
          inoculationAmount: null,
          purchaseHeadId: null,
          customerStatus: null,
          customerSource: null,
          customerTransationAnalysis: null,
          specialRequirement: null,
          paymentCycle: null,
          medicinePaymentMethod: null,
          warehouseDelivery: null,
          supplierAbbreviation: null,
          saleHeadId: null,
          saleContactId: null,
          supplierStatus: null,
          supplierSource: null,
          supplierType: null,
          supplierLevel: null,
          supplierOrganizationalRelationship: null,
          supplierPolicySupport: null,
          loanCycle: null,
          supplierPaymentMethod: null,
          dealStatus: null,
          dealTime: null,
          nextContactTime: null,
          inputMethod: null,
          informationCompleteness: null,
          status: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null
        }
        this.resetForm("basicInfoForm")
      },
    }

  }
</script>

<style>
</style>
